﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class CollideTool
{
    //与平台碰撞时，获取碰撞面法线的向量，仅适用于与方形平台碰撞时
    public static Vector2 NormalLineOfCollide(Bounds bounds,Vector2 hitPoint)
    {
        hitPoint = bounds.ClosestPoint(hitPoint);
        if(bounds.max.x == hitPoint.x)
            return Vector2.right;
        else if(bounds.min.x == hitPoint.x)
            return Vector2.left;
        if(bounds.max.y == hitPoint.y)
            return Vector2.up;
        else if(bounds.min.y == hitPoint.y)
            return Vector2.down;
        return Vector2.zero;
    }
}
